<template>
    <div>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media" v-for="(item,index) in newsList" :key="item.image">
                <!-- 使用index来模拟每篇文章唯一的id属性 -->
                <router-link :to="'/home/newsinfo/'+ (index+1)">
                    <img class="mui-media-object mui-pull-left" :src="item.image">
                    <div class="mui-media-body">
                        <h1>{{item.title}}</h1>
                        <p class='mui-ellipsis'>
                            <span>发表时间:{{item.passtime | dataFormat}}</span>
                            <span>点击:1次数</span>
                        </p>
                    </div>
                </router-link>
            </li> 
        </ul>
    </div>
</template>

<script>
import { METHODS } from 'http';
import { Toast } from 'mint-ui';
export default {
    data(){
        return {
            newsList:[]//新闻列表数据
        }
    },
    created(){
        this.getNewsList();
    },
    methods:{
        getNewsList(){//获取新闻列表
            this.$http.get('https://api.apiopen.top/getWangYiNews?count=20').then(res=>{
                // console.log(res); //查看响应后返回的响应体的内容以及格式
 
                if (res.body.code===200) {
                    // 如果没有失败，把我们的数据保存到 data 中去
                    this.newsList = res.body.result;
                }else{
                    Toast('获取信息失败了...')
                }
            })
        }
    }
}
</script>


<style lang="scss" scoped>
.mui-table-view {
    li {
        h1 {
            font-size: 14px;
        }
        .mui-ellipsis {
           font-size: 12px; 
           color: #226aff; 
        //    设置flex布局，让内容两边显示
           display: flex;
           justify-content: space-between;
        }
    }
}
</style>
